package com.kafka.controller;

import com.kafka.config.KafkaSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @descriptions: 发送消息
 * @author: yunqiang
 * @date: 2022/1/5 12:30
 */
@RestController
@RequestMapping("/sendMessage")
public class SendMessageController {

    @Autowired
    private KafkaSender kafkaSender;

    @GetMapping("/v1/test")
    public String test1(String name) {
        try {
            kafkaSender.sendMesssageNoWrap("tt", "123KEY", name);
        } catch (Exception e) {
            return "发送失败"+e.toString();
        }
        return "发送成功";
    }

    @GetMapping("/v2/test")
    public String test2(String key,String name) {
        try {
            Test test = new Test();
            test.setData(name);
            kafkaSender.sendMesssage("tt", key, test);
        } catch (Exception e) {
            return "发送失败"+e.toString();
        }
        return "发送成功";
    }
}
